/**
 * ReportGear(2011)
 */
package com.reportgear.core.data;

import java.util.List;
import java.util.Set;

import org.dom4j.Attribute;
import org.dom4j.Document;
import org.dom4j.Element;

import com.reportgear.core.data.model.SalaryDataObject;
import com.reportgear.core.xml.Dom4jUtils;
import com.reportgear.report.model.cell.value.salary.SalaryObjectType;
import com.sot.core.util.StringUtils;

/**
 * 通过本地方式查询XML数据，一般用于测试
 * 
 * @version 1.0 2011-5-28
 * @author <a herf="lexloo@gmail.com">lexloo</a>
 * @since Report 1.0
 */
public class SalaryDataQueryXmlByLocal extends AbstractSalaryDataQueryXml {
	@Override
	public List<SalaryDataObject> getOrgs() {
		return this.xmlDataToList(this.loadLocalXml("GetOrgs.ashx"));
	}

	@Override
	public List<SalaryDataObject> getCenters() {
		return this.xmlDataToList(this.loadLocalXml("GetCenters.ashx"));
	}

	@Override
	public List<SalaryDataObject> getSalaryScheme() {
		return this.xmlDataToList(this.loadLocalXml("GetSalarySystems.ashx"));
	}

	@Override
	public List<SalaryDataObject> getSalaryItem(int schemeId) {
		return this.xmlDataToList(this.loadLocalXml("GetSalaryItemsBySysID.ashx"));
	}

	@Override
	public List<SalaryDataObject> getPayTotal(int payId, SalaryObjectType objectType, int level, Set<Integer> rowSet,
			Set<Integer> colSet) {
		return this.xmlDataToList(this.loadLocalXml("GetQueryDataByTemplate.ashx"));
	}

	@Override
	public List<SalaryDataObject> getPayDoc(int paymentId, SalaryObjectType objectType, int level, Set<Integer> rowSet,
			Set<Integer> colSet) {
		return this.xmlDataToList(this.loadLocalXml("GetQueryDocByTemplate.ashx"));
	}

	@Override
	public List<SalaryDataObject> getPayDetail(int paymentId, SalaryObjectType objectType, int level,
			Set<Integer> rowSet, Set<Integer> colSet) {
		return this.xmlDataToList(this.loadLocalXml("GetQueryDetailByTemplate.ashx"));
	}

	@Override
	public String loadTemplate(int reportId) {
		return this.loadLocalXml("GetTemplateByID.ashx");
	}

	@Override
	public List<SalaryDataObject> loadTemplateList() {
		return this.xmlDataToList(this.loadLocalXml("GetTemplates.ashx"));
	}

	@Override
	public int saveTemplate(String template, int id, int SystemId, String name) {
		System.out.println(template);
		return 0;
	}

	@Override
	public boolean deleteTemplate(int id) {
		return true;
	}

	@Override
	public List<SalaryDataObject> getLastPayments() {
		return this.xmlDataToList(this.loadLocalXml("GetSalaryPayInfos.ashx"));
	}

	@Override
	public SalaryDataObject getSessionVar() {
		return this.xmlRootToList(this.loadLocalXml("GetUserInfo.ashx"));
	}
	
	@Override
	public List<SalaryDataObject> getPayObjects(int paymentId, SalaryObjectType objectType, int level,
			Set<Integer> rowSet, Set<Integer> colSet) {
		return this.xmlDataToList(this.loadLocalXml("GetObjectsByPID.ashx"));
	}

	@Override
	public SalaryDataObject getPayBase(int payId) {
		Document doc = Dom4jUtils.createDocument(this.loadLocalXml("GetSalaryPayInfo.ashx"));
		Element root = doc.getRootElement();

		SalaryDataObject sdo = new SalaryDataObject();
		for (Object ao : root.attributes()) {
			Attribute aa = (Attribute) ao;

			sdo.setValue(aa.getName(), StringUtils.trim(aa.getValue()));
		}

		return sdo;
	}

	@Override
	public List<SalaryDataObject> getOrderInfo(String key) {
		return this.xmlDataToList(this.loadLocalXml("GetSalaryQuerySettingInfo.ashx"));
	}

	@Override
	public int saveOrderInfo(String key, String content) {
		System.out.println(content);
		return 1;
	}

	private String loadLocalXml(String id) {
		Document doc = Dom4jUtils.createDocumentFromFile("c:\\\\report\\" + id + ".xml");

		return doc.asXML();
	}
}
